import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;


public class ConductComponents extends JPanel implements ActionListener {
	
	private SystemEssentials gui = new SystemEssentials(10);
	private JButton bConduct, bCo, bRHGP;
	private JCheckBox cView[] = new JCheckBox[4];
	private JComboBox cbFilterBy, cbStatus;
	public String[] sFilterBy = {"---", "Status", "Position", "Area", "Sections Handled"};
	public String[] sStatus = {"---", "Active", "Grades"};
	
	private ImageIcon iConduct = new ImageIcon("gui/buttons/bConduct.png"),
					  iConduct_ = new ImageIcon("gui/buttons/bConduct_.png"),
	  				  iCo = new ImageIcon("gui/buttons/bCo.png"),
	  				  iCo_ = new ImageIcon("gui/buttons/bCo_.png"),
	  				  iRHGP = new ImageIcon("gui/buttons/bRHGP.png"),
	  				  iRHGP_ = new ImageIcon("gui/buttons/bRHGP_.png");
	
	public ConductComponents(){
		setLayout(null);
		setBounds(0,0,700,600);	
		setOpaque(false);

		refreshTable();
		createGui();		
	}
	
	public void createGui(){
		for(int i=0; i<4; i++){
			cView[i] = new JCheckBox();
			cView[i].addActionListener(this);
			cView[i].setSelected(true);
			switch(i){
			case 0: cView[i].setText("ID"); break;
			case 1: cView[i].setText("Status"); break;
			case 2: cView[i].setText("Component Name"); break;
			case 3: cView[i].setText("Percentage"); break;
			}
			cView[i].setBounds(25,440+(i*19),140,19);
			if(i==4)
				cView[4].setVisible(false);
			add(cView[i]);
		}
		
		cbFilterBy = new JComboBox(sFilterBy);
		cbFilterBy.setBounds(170,440,190,30);
		cbFilterBy.addActionListener(this);
		add(cbFilterBy);
		
		cbStatus = new JComboBox(sStatus);
		cbStatus.setBounds(170,480,190,30);
		add(cbStatus);
						
		bConduct = new JButton(iConduct);
		bConduct.setBounds(600,105,75,18);
		bConduct.setRolloverIcon(iConduct_);
		bConduct.setBorderPainted(false);
		bConduct.setContentAreaFilled(false);
		bConduct.setVisible(true);
		bConduct.addActionListener(this);
		add(bConduct);
		
		bCo = new JButton(iCo);
		bCo.setBounds(476,105,122,18);
		bCo.setRolloverIcon(iCo_);
		bCo.setBorderPainted(false);
		bCo.setContentAreaFilled(false);
		bCo.setVisible(true);
		bCo.addActionListener(this);
		add(bCo);
		
		bRHGP = new JButton(iRHGP);
		bRHGP.setBounds(420,105,54,18);
		bRHGP.setRolloverIcon(iRHGP_);
		bRHGP.setBorderPainted(false);
		bRHGP.setContentAreaFilled(false);
		bRHGP.setVisible(true);
		bRHGP.addActionListener(this);
		add(bRHGP);
		
		add(gui);		
	}
		
	public void actionPerformed(ActionEvent a) {
		if(a.getSource() == bConduct){
			MainPanel.goToPage(7);
		}
		if(a.getSource() == bCo){
			MainPanel.goToPage(9);
		}
		if(a.getSource() == bRHGP){
			MainPanel.goToPage(10);
		}
	}
		
	public void refreshTable(){
		gui.resetTableModel(10);
		// for input data from sql
		for(int i=0; i<1; i++){
			Vector<String> rowData = new Vector<String>();
			//sample
			rowData.add("1001");
			rowData.add("Active");
			rowData.add("Love for God");
			rowData.add("20%");
			//sample
			gui.model.addRow(rowData);
		}

		for(int i=0; i<gui.model.getColumnCount(); i++){
			gui.table.getColumnModel().getColumn(i).setCellRenderer(gui.cellRenderer);
			gui.setColumnWidth(i,1);
		}
		
		for(int i=0; i<1; i++){
			Vector<String> rowData = new Vector<String>();
			//sample
			rowData.add("1002");
			rowData.add("Active");
			rowData.add("Love for Country");
			rowData.add("20%");
			//sample
			gui.model.addRow(rowData);
		}

		for(int i=0; i<gui.model.getColumnCount(); i++){
			gui.table.getColumnModel().getColumn(i).setCellRenderer(gui.cellRenderer);
			gui.setColumnWidth(i,1);
		}
		
		for(int i=0; i<1; i++){
			Vector<String> rowData = new Vector<String>();
			//sample
			rowData.add("1003");
			rowData.add("Active");
			rowData.add("Love for Work");
			rowData.add("20%");
			//sample
			gui.model.addRow(rowData);
		}

		for(int i=0; i<gui.model.getColumnCount(); i++){
			gui.table.getColumnModel().getColumn(i).setCellRenderer(gui.cellRenderer);
			gui.setColumnWidth(i,1);
		}
		
		for(int i=0; i<1; i++){
			Vector<String> rowData = new Vector<String>();
			//sample
			rowData.add("1004");
			rowData.add("Active");
			rowData.add("Love for Others");
			rowData.add("20%");
			//sample
			gui.model.addRow(rowData);
		}

		for(int i=0; i<gui.model.getColumnCount(); i++){
			gui.table.getColumnModel().getColumn(i).setCellRenderer(gui.cellRenderer);
			gui.setColumnWidth(i,1);
		}
		
		for(int i=0; i<1; i++){
			Vector<String> rowData = new Vector<String>();
			//sample
			rowData.add("1005");
			rowData.add("Active");
			rowData.add("Love for Self");
			rowData.add("20%");
			//sample
			gui.model.addRow(rowData);
		}

		for(int i=0; i<gui.model.getColumnCount(); i++){
			gui.table.getColumnModel().getColumn(i).setCellRenderer(gui.cellRenderer);
			gui.setColumnWidth(i,1);
		}
	}
		
	public void refreshGUI(){
		refreshTable();
		gui.refreshGUI();
	}
}
